package com.sqpoll.android;

import java.util.ArrayList;
import java.util.List;

import android.content.res.Resources;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.actionbarsherlock.app.SherlockFragment;
import com.actionbarsherlock.view.Menu;
import com.actionbarsherlock.view.MenuInflater;
import com.sqpoll.android.poll.HomePollListAdapter;
import com.sqpoll.android.poll.Poll;
import com.sqpoll.android.widget.ExpandableHeightGridView;

/**
 * The fragment for home.
 * 
 * @author Younggue Bae
 */
public class HomeFragment_1 extends SherlockFragment {

	public static final String TAG = "HomeFragment";
	
	private ExpandableHeightGridView mListViewLeft;
	private ExpandableHeightGridView mListViewRight;
	private HomePollListAdapter mAdapterLeft;
	private HomePollListAdapter mAdapterRight;
	private List<Poll> mItemsLeft;
	private List<Poll> mItemsRight;

	int[] mLeftViewsHeights;
	int[] mRightViewsHeights;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setHasOptionsMenu(true);
	}
	
	@Override
  public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
		inflater.inflate(R.menu.fragment_home, menu);
    super.onCreateOptionsMenu(menu, inflater);
  }

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_home, container, false);
		
		mListViewLeft = (ExpandableHeightGridView) view.findViewById(R.id.list_view_left);
		mListViewRight = (ExpandableHeightGridView) view.findViewById(R.id.list_view_right);
		mListViewLeft.setExpanded(true);
		mListViewRight.setExpanded(true);

		loadItems();
		
		mAdapterLeft = new HomePollListAdapter(getActivity(), R.layout.list_item_poll, mItemsLeft);
		mAdapterRight = new HomePollListAdapter(getActivity(), R.layout.list_item_poll, mItemsRight);
		mListViewLeft.setAdapter(mAdapterLeft);
		mListViewRight.setAdapter(mAdapterRight);
		
		return view;
	}

	private void loadItems() {
		Resources res = getResources();
		
		mItemsLeft = new ArrayList<Poll>();
		mItemsRight = new ArrayList<Poll>();
		
		Poll poll = new Poll();
		poll.setPollImage(res.getDrawable(R.drawable.ic_1));
		poll.setUsername("Sonya Cho");
		poll.setCreateDate("1 day ago");
		poll.setStatus("open");
		poll.setQuestion("Do you like this food?");
		poll.setCommentCount(10);
		poll.setVoterCount(17);
		
		mItemsLeft.add(poll);
		
		poll = new Poll();
		poll.setPollImage(res.getDrawable(R.drawable.ic_2));
		poll.setUsername("Younggue Bae");
		poll.setCreateDate("06.07");
		poll.setStatus("open");
		poll.setQuestion("Do you like this news?");
		poll.setCommentCount(5);
		poll.setVoterCount(10);
		
		mItemsLeft.add(poll);
		
		poll = new Poll();
		poll.setPollImage(res.getDrawable(R.drawable.ic_3));
		poll.setUsername("Sonya Cho");
		poll.setCreateDate("1 day ago");
		poll.setStatus("open");
		poll.setQuestion("Do you like this food?");
		poll.setCommentCount(10);
		poll.setVoterCount(17);
		
		mItemsLeft.add(poll);
		
		poll = new Poll();
		poll.setPollImage(res.getDrawable(R.drawable.ic_4));
		poll.setUsername("Sonya Cho");
		poll.setCreateDate("1 day ago");
		poll.setStatus("open");
		poll.setQuestion("Do you like this food?");
		poll.setCommentCount(10);
		poll.setVoterCount(17);
		
		mItemsLeft.add(poll);
		
		poll = new Poll();
		poll.setPollImage(res.getDrawable(R.drawable.ic_5));
		poll.setUsername("Sonya Cho");
		poll.setCreateDate("1 day ago");
		poll.setStatus("open");
		poll.setQuestion("Do you like this food?");
		poll.setCommentCount(10);
		poll.setVoterCount(17);
		
		mItemsLeft.add(poll);

		poll = new Poll();
		poll.setPollImage(res.getDrawable(R.drawable.ic_6));
		poll.setUsername("Sonya Cho");
		poll.setCreateDate("1 day ago");
		poll.setStatus("open");
		poll.setQuestion("Do you like this food?");
		poll.setCommentCount(10);
		poll.setVoterCount(17);
		
		mItemsRight.add(poll);
		
		poll = new Poll();
		poll.setPollImage(res.getDrawable(R.drawable.ic_7));
		poll.setUsername("Younggue Bae");
		poll.setCreateDate("06.07");
		poll.setStatus("open");
		poll.setQuestion("Do you like this news?");
		poll.setCommentCount(5);
		poll.setVoterCount(10);
		
		mItemsRight.add(poll);
		
		poll = new Poll();
		poll.setPollImage(res.getDrawable(R.drawable.ic_8));
		poll.setUsername("Sonya Cho");
		poll.setCreateDate("1 day ago");
		poll.setStatus("open");
		poll.setQuestion("Do you like this food?");
		poll.setCommentCount(10);
		poll.setVoterCount(17);
		
		mItemsRight.add(poll);
		
		poll = new Poll();
		poll.setPollImage(res.getDrawable(R.drawable.ic_9));
		poll.setUsername("Sonya Cho");
		poll.setCreateDate("1 day ago");
		poll.setStatus("open");
		poll.setQuestion("Do you like this food?");
		poll.setCommentCount(10);
		poll.setVoterCount(17);
		
		mItemsRight.add(poll);
		
		poll = new Poll();
		poll.setPollImage(res.getDrawable(R.drawable.ic_10));
		poll.setUsername("Sonya Cho");
		poll.setCreateDate("1 day ago");
		poll.setStatus("open");
		poll.setQuestion("Do you like this food?");
		poll.setCommentCount(10);
		poll.setVoterCount(17);
		
		mItemsRight.add(poll);
	}
	
}
